#include "interrupts.h"
#include "defs.h"
#include "video.h"
#include "keyboard.h"
#include "uart.h"
#include "kasm.h"


/* Variables Globales */
int numlock=0, caps=0, scrolllock=0;
char format= WHITE_TXT;
static int rshift=0, lshift=0;
extern int screen_pos;
extern int r_screen_pos;
extern int commNum;
extern unsigned char history[MAX_COMM][COMM_LEN+1];
extern bufferT buff;
extern int prompt_pos;
extern int com_port;
int d_cant_rows = CANT_ROWS;
int d_frow = 0;
int serialc;
int serialo=0;

void int_08()
{
    return;
}

void int_09(int scancode)			/* Interrupcion de teclado */
{
	unsigned char c;
    
    _Cli();

    if(scancode == SRSHIFT)			/* Prendo los shift */
		rshift = 1;
	else if(scancode == SLSHIFT)
		lshift = 1;
	else if(scancode == (SRSHIFT | BREAK_MASK))	/* Apago los shift */
		rshift = 0;
	else if(scancode == (SLSHIFT | BREAK_MASK))
		lshift = 0;
	else if(scancode == CAPSLOCK && caps == 0)
	{
		caps = 1;
		setLights();
	}
	else if(scancode == CAPSLOCK && caps == 1)
	{
		caps = 0;
		setLights();
	}
	else if(scancode == NUMLOCK)
	{
		numlock = !numlock;
		setLights();
	}
	else if(scancode == SCROLLLOCK)
	{
		scrolllock = !scrolllock;
		setLights();
	}
	else
	{
		/* si el scancode no esta mapeado no hago nada */
    	if (scancode >= CANT_KEYS)
    		return;

		c = ctoa(scancode, lshift || rshift, caps);
		
		AddToBuffer(c, &buff);
	}
    
    _Sti();
    
	return ;
}

void int_0C()			/* Interrucpion de COM1 */
{
    int aux, auxf, r;
    _Cli();
    serialc = readFromUART (com_port);
    _Sti();
    
    serialo = 1;
    
	return ;
}

void int_80(FD fd, const void * buff, int size)		/* Interrucpion de write */
{
	char * video = (char *) 0xb8000;
    int i;
    
    _Cli();
    for(i = 0; i < size; i++)
    {
        video[screen_pos++]= *((char*)buff+i);
        video[screen_pos++]= format;
    }
    _Sti();
}
